package entity;

import java.util.HashMap;
import java.util.Map;

public class Return {
    private Boolean success;

    private Integer code;

    private String message;

    private Map<String, Object> data = new HashMap<String, Object>();

    public Return() {
    }

    public static Return ok(){
        Return r = new Return();
        r.setSuccess(true);
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    public static Return error(){
        Return r = new Return();
        r.setSuccess(false);
        r.setCode(201);
        r.setMessage("失败");
        return r;
    }

    public Return success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public Return message(String message){
        this.setMessage(message);
        return this;
    }

    public Return code(Integer code){
        this.setCode(code);
        return this;
    }

    public Return data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public Return data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Return{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
